#ifndef LOGINTASK_H
#define LOGINTASK_H
#include "libs/base/service/request.h"
#include "libs/base/task/task.h"
#include "libs/core/user/loginuser.h"

namespace yc {
class Downloader;
}

class LoginTask : public yc::Task
{
    Q_OBJECT
public:
    explicit LoginTask(const yc::LoginUser& user, QObject* parent = nullptr);
    LoginTask(const QString& name, const QString& pwd, const QString& code,
              QObject* parent = nullptr);

    const QString& code() const { return code_; }

private:
    void onRefresh(const yc::Request& request, const yc::Response& response);
    void onResponse(const yc::Request& request, const yc::Response& response);
    void startImpl() override;

    yc::LoginUser user_;
    QString password_;
    QString code_;
    bool use_token_;
    QPointer<yc::Downloader> downloader_;
};

#endif // LOGINTASK_H
